<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/jquery-1.11.1.js"></script>
</head>

<button onclick="login()">登录</button>

<div style="border: black solid 1px;padding: 1rem 1rem 1rem 1rem">
    <button onclick="wechatLogin()">vx登录</button>
    &nbsp;
    <button onclick="checkLogin()">check登录</button>
    &nbsp;
    <button onclick="startOpen()">开抢</button>


</div>

<br/>
<br/>
<button onclick="selectList()">查询</button>

<br/><br/>
<button onclick="out()">退出</button>
<br/><br/>
<br/>
<div id=msg>
</div>
<div id="table"></div>
<br/>

<img src="">


<body>
<script>
    var token;
    // var ip = "http://124.221.64.146:8080/";
    var ip = "http://127.0.0.1:8080/";
    //系统登录
    function login() {
        $.ajax({
            url: ip + 'Gold/login',
            data: {
                username: "admin",
                password: "123456"
            },
            type: 'post',
            success: function (res) {
                var obj = JSON.parse(JSON.stringify(res));
                token = obj.data.Token
                $("#msg").html(res.message)
            }
        })
    }
    var uuid = "";
    var WxId = "xx";
    //微信登录
    function wechatLogin() {
        $.ajax({
            url: ip + 'Gold/wechat/Login/GetQrCode',
            headers: {
                token: token
            },
            //  data: JSON.stringify({"page": "1", "size": "10"}),
            contentType: 'application/json;charset=UTF-8',
            type: 'post',
            success: function (res) {

                var obj = JSON.parse(res);
                $("img").attr("src","data:image/jpeg;base64,"+obj.Data.Data)
                console.log(obj.Data.Uuid)
                uuid = obj.Data.Uuid;

            }
        })
    }

    //检查登录
    function checkLogin() {
        $.ajax({
            url: ip + 'Gold/wechat/Login/CheckLogin',
            headers: {
                token: token
            },
            data: JSON.stringify({"uuid": uuid}),
            contentType: 'application/json;charset=UTF-8',
            type: 'post',
            success: function (res) {
                var obj = JSON.parse(res);

               // WxId = obj.Data.WxId;

                console.log(obj)
            }
        })
    }

    //开启抢红包
    function startOpen() {
        $.ajax({
            url: ip + 'Gold/wechat/Pay/StartOpenRedEnvelopes',
            headers: {
                token: token
            },
            data: JSON.stringify({"second": 2, "wxId": WxId}),
            contentType: 'application/json;charset=UTF-8',
            type: 'post',
            success: function (res) {
                console.log(WxId)

                var obj = JSON.parse(res);
                console.log(obj)
            }
        })
    }



    function selectList() {
        $.ajax({
            url: ip + 'Gold/card/getList',
            headers: {
                token: token
            },
            data: JSON.stringify({"page": "1", "size": "10"}),
            contentType: 'application/json;charset=UTF-8',
            type: 'post',
            success: function (res) {
                $("#msg").html(res.message)
                console.log(res)
                $("#table").html(res)
            }
        })
    }


    function out() {
        $.ajax({
            url: ip + 'Gold/logout',
            headers: {
                token: token
            },
            contentType: 'application/json;charset=UTF-8',
            type: 'post',
            success: function (res) {
                $("#msg").html(res.message)
                console.log(res);
            }
        })
    }
</script>
</body>

</html>